﻿// Autore: Emanuele Poggi

using System.Threading;
using RecipesManager.Data;
using White.Core.UIItems;
using White.Core.UIItems.WindowItems;
using Application = White.Core.Application;
using Button = White.Core.UIItems.Button;
using ComboBox = White.Core.UIItems.ListBoxItems.ComboBox;
using ListView = White.Core.UIItems.ListView;
using TextBox = White.Core.UIItems.TextBox;

namespace RecipesManager.Specs.Evento
{
    public class EventiBdd
    {
        protected const string ManagerTitle = "Gestione Eventi";

        protected Window MainWindow;
        protected Application Application;
        protected Button NewEvent;
        protected Button RemoveEvent;
        protected Button BackToMainMenu;
        protected ListView EventsList;
        protected Button ClosedEvents;
        protected ListView ClosedEventsList;

        protected Button Note;
        protected Button CloseEvent;
        protected TextBox EventName;
        protected TextBox EventDate;
        protected System.Windows.Controls.TextBlock EventNote;
        protected ComboBox EventsGuests;
        protected IUIItem SelectedEventsGuests;
        protected Button AddEventGuest;
        protected Button RemoveEventGuest;
        protected ComboBox Menu;
        protected IUIItem SelectedMenu;
        protected Button AddRecipe;
        protected Button RemoveRecipe;

        protected Button Close;
        protected Button Save;
        protected Button EventCalendar;
        protected Button AddMenuToShoppingList;

        protected Button AddRecipeToList;
        protected Button RemoveRecipeFromList;

        protected ListView Conflicts;
        protected void GetSingleEventUi()
        {
            EventName = MainWindow.Get<TextBox>("tb_nomeEvento");
            Note = MainWindow.Get<Button>("PART_DropDownButton");
            CloseEvent = MainWindow.Get<Button>("tb_closeEvent");

            EventCalendar = MainWindow.Get<Button>("_calendarToggleButton");
            EventDate = MainWindow.Get<TextBox>("PART_TextBox");
            //EventNote = MainWindow.Get<TextBox>("tb_notes");

            EventsGuests = MainWindow.Get<ComboBox>("cb_invitati");
            //SelectedEventsGuests = MainWindow.Get<ListView>("gb_listaInvitati");
            AddEventGuest = MainWindow.Get<Button>("bt_addGuest");
            RemoveEventGuest = MainWindow.Get<Button>("bt_cancGuest");

            Menu = MainWindow.Get<ComboBox>("cb_ricette");
            SelectedMenu = MainWindow.Get<ListView>("lb_menuRicette");
            AddRecipe = MainWindow.Get<Button>("bt_addMenu");
            RemoveRecipe = MainWindow.Get<Button>("bt_cancMenu");
            AddRecipeToList = MainWindow.Get<Button>("bt_addRtSL");
            RemoveRecipeFromList = MainWindow.Get<Button>("bt_delRtSL");

            Close = MainWindow.Get<Button>("bt_chiudi");
            Save = MainWindow.Get<Button>("bt_salva");
            AddMenuToShoppingList = MainWindow.Get<Button>("bt_addAllRtSL");

           Conflicts = MainWindow.Get<ListView>("lb_conflitti");
        }

        protected void GetEventUi()
        {
            NewEvent = MainWindow.Get<Button>("bt_add");
            RemoveEvent = MainWindow.Get<Button>("bt_delete");
            BackToMainMenu = MainWindow.Get<Button>("bt_back");
            EventsList = MainWindow.Get<ListView>("lw_eventi");
            ClosedEvents = MainWindow.Get<Button>("tb_evChiusi");
        }

        protected void SetUpScenario()
        {
            Manager.ClearDatabase();
            Manager.Measures.Add("grammi", "gr", MeasureType.Weight, MeasureFamily.Metric, 1);
            Manager.Measures.Add("PesoTest", "PT", MeasureType.Weight, MeasureFamily.Metric, 1);
            Application = Application.Launch(@"..\..\..\RecipesManager\bin\x86\WhiteTesting\RecipesManager.exe");
            MainWindow = Application.GetWindow("Recipes Manager");
        }

        protected void TearDownScenario()
        {
            Manager.ClearCache();
            Manager.ClearDatabase();
            Thread.Sleep(2000);
            Application.Kill();
        }

        protected void NavigateToMainMenu()
        {
            MainWindow.Get<Button>("bt_back").Click();
            MainWindow = Application.GetWindow("Recipes Manager");
        }

        protected void NavigateToEvents()
        {
            MainWindow.Get<Button>("eventi").Click();
            MainWindow = Application.GetWindow(ManagerTitle);
        }

        protected void GetPassedEventsUi()
        {
            ClosedEventsList = MainWindow.Get<ListView>("lw_eventiPassati");
        }
        
    }
}